﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BlockLogic.Impl.Blocks.Checker.Enum;
using BlockLogic.Impl.Controller;
using BlockLogic.Interface.Blocks.Checker;
using CommandLogic.Interface;

namespace CommandLogic.Impl
{
    public class UpdateHistogramCommand : ICommandLogic
    {
        private static UpdateHistogramCommand instance = new UpdateHistogramCommand();

        private UpdateHistogramCommand() { }

        public static UpdateHistogramCommand GetInstance()
        {
            return instance;
        }

        public Dictionary<string, object> execute(Dictionary<string, object> param)
        {
            var id = (Guid)param["id"];

            var blocks = BlockController.GetInstance();

            var checkerBlockParams = new Dictionary<string, object>();

            var state = ((ICheckerBlock)blocks[id]).ReturnParameters[CheckerParameter.STATE];
            checkerBlockParams.Add("STATE", state);

            if ("NO_DATA" == state.ToString())
            {
                return checkerBlockParams;
            }

            var degreesOfFreedom = ((ICheckerBlock)blocks[id]).ReturnParameters[CheckerParameter.DEGREES_OF_FREEDOM];
            checkerBlockParams.Add("DEGREES_OF_FREEDOM", degreesOfFreedom);
            
            var pearsonCriterion = ((ICheckerBlock)blocks[id]).ReturnParameters[CheckerParameter.PEARSON_CRITERION];
            checkerBlockParams.Add("PEARSON_CRITERION", pearsonCriterion);
            
            var points = ((ICheckerBlock)blocks[id]).ReturnParameters[CheckerParameter.POINTS];
            checkerBlockParams.Add("POINTS", points);

            var theorpoints = ((ICheckerBlock)blocks[id]).ReturnParameters[CheckerParameter.THEORETICAL_POINTS];
            checkerBlockParams.Add("THEORETICAL_POINTS", theorpoints);

            var count = ((ICheckerBlock)blocks[id]).ReturnParameters[CheckerParameter.COUNT];
            checkerBlockParams.Add("COUNT", count);

            return checkerBlockParams;
        }
    }
}
